"""
Case Type   : fullsql
Case Name   : 新增GUC参数默认值校验
Create At   : 2022/01/30
Owner       : zhao-pengcheng-g
Description :
    1.验证statement_stat_level参数默认值为OFF,L0
    2.验证statement_reserve_count参数默认值为1000
    3.验证statement_retention_time参数默认值为3600,604800
    4.验证statement_details_size参数默认值为4096
    5.验证enable_stmt_track参数默认值为on
Expect      :
    1.OFF,L0
    2.1000
    3.3600,604800
    4.4096
    5.on
History     :
"""

import unittest
from yat.test import Node
from yat.test import macro
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger
from testcase.utils.Common import Common


class Fullsql(unittest.TestCase):
    def setUp(self):
        self.logger = Logger()
        text = '---Opengauss_Function_Fullsql_Case0023 start---'
        self.logger.info(text)
        self.userNode = Node('PrimaryDbUser')
        self.sh_primy = CommonSH('PrimaryDbUser')
        self.constant = Constant()
        self.common = Common()

    def test_fullsql(self):
        text = '---step1:验证statement_stat_level参数默认值为OFF,L0,' \
               'expect:成功---'
        self.logger.info(text)
        show_cmd = f'''show track_stmt_stat_level;'''
        show_msg = self.sh_primy.execut_db_sql(show_cmd)
        self.logger.info(show_msg)
        self.common.equal_sql_mdg(show_msg, 'track_stmt_stat_level',
                                  'OFF,L0', '(1 row)', flag='1')

        text = '---step2:验证statement_reserve_count参数默认值为1000,' \
               'expect:成功---'
        self.logger.info(text)
        show_cmd = f'''show track_stmt_session_slot;'''
        show_msg = self.sh_primy.execut_db_sql(show_cmd)
        self.logger.info(show_msg)
        self.common.equal_sql_mdg(show_msg, 'track_stmt_session_slot', '-------------------------', ' 1000', '(1 row)')

        text = '---step3:验证statement_retention_time参数默认值为3600,604800,' \
               'expect:成功---'
        self.logger.info(text)
        show_cmd = f'''show track_stmt_retention_time;'''
        show_msg = self.sh_primy.execut_db_sql(show_cmd)
        self.logger.info(show_msg)
        self.common.equal_sql_mdg(show_msg, 'track_stmt_retention_time',
                                  '3600,604800', '(1 row)', flag='1')

        text = '---step4:验证statement_details_size参数默认值为4096,' \
               'expect:成功---'
        self.logger.info(text)
        show_cmd = f'''show track_stmt_details_size;'''
        show_msg = self.sh_primy.execut_db_sql(show_cmd)
        self.logger.info(show_msg)
        self.common.equal_sql_mdg(show_msg, 'track_stmt_details_size',
                                  '4096', '(1 row)', flag='1')

        text = '---step5:验证enable_stmt_track参数默认值为on,expect:成功---'
        self.logger.info(text)
        show_cmd = f'''show enable_stmt_track;'''
        show_msg = self.sh_primy.execut_db_sql(show_cmd)
        self.logger.info(show_msg)
        self.common.equal_sql_mdg(show_msg, 'enable_stmt_track',
                                  'on', '(1 row)', flag='1')

    def tearDown(self):
        self.logger.info(
            '---Opengauss_Function_Fullsql_Case0023 finish---')
